package loan.calc.service.loan.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import loan.calc.domain.LoanRepaymentScheduleDO;
import loan.calc.dto.LoanRepaymentScheduleDTO;
import loan.calc.mapper.LoanRepaymentScheduleMapper;
import loan.calc.service.loan.LoanRepayScheduleService;
import loan.calc.util.POJOConverter;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class LoanRepayScheduleServiceImpl extends ServiceImpl<LoanRepaymentScheduleMapper, LoanRepaymentScheduleDO> implements LoanRepayScheduleService {
    @Override
    public List<LoanRepaymentScheduleDTO> getRepayScheduleListByLoanId(Long loanId) {
        return lambdaQuery().eq(LoanRepaymentScheduleDO::getLoanId, loanId).list()
                .stream().map(domain -> POJOConverter.convert(LoanRepaymentScheduleDTO.class, domain))
                .collect(Collectors.toList());
    }
}
